 package com.gmrz.uaf.protocol.v1.processor;
 
 import java.security.SecureRandom;
import java.util.Properties;

 import com.gmrz.service.logpool.LogPoolManager;
 import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.inject.name.Names;
import com.gmrz.service.challengestore.ChallengeStoreService;
import com.gmrz.uaf.common.UAFBaseModule;
import com.gmrz.uaf.common.UAFRuntimeException;
import com.gmrz.uaf.common.service.challengestore.UAFChallengeStoreServiceProvider;
import com.gmrz.uaf.common.service.challengestore.UAFChallengeStoreUtil;
import com.gmrz.uaf.db.UAFDBConnectionMgr;
import com.gmrz.uaf.policy.PolicyManager;
import com.gmrz.uaf.policy.json.JSONPolicyManager;
import com.gmrz.uaf.protocol.v1.schema.OperationHeader;
import com.gmrz.uaf.server.ServerConfig;
 
 public class UAFProcessorModule extends UAFBaseModule
 {
   private static final Logger LOG = LogManager.getLogger(UAFProcessorModule.class);
 
   public UAFProcessorModule(Properties uafProperties) {
     
	   super(uafProperties);
 
     if (uafProperties == null) {
       String errorMessage = "Module properties object cannot be null.";
       LOG.error(errorMessage);
       throw new UAFRuntimeException(errorMessage);
     }
 
     this.moduleConfigurations.addAll(ServerConfig.getAllConfigurations());
   }
 
   protected void configure() {
     super.configure();
 
     bind(Properties.class).annotatedWith(Names.named("uaf.properties")).toInstance(this.moduleProperties);
 
     bind(UAFDBConnectionMgr.class).asEagerSingleton();

     bind(LogPoolManager.class).asEagerSingleton();
 
     bind(PolicyManager.class).to(JSONPolicyManager.class);
 
     bind(ServerConfig.class).asEagerSingleton();
 
     bind(UAFChallengeStoreUtil.class).asEagerSingleton();
 
     bind(ChallengeStoreService.class).toProvider(UAFChallengeStoreServiceProvider.class);
 
     bind(OperationHeader.class).annotatedWith(Names.named("registration")).toProvider(RegOpHeaderProvider.class);
 
     bind(OperationHeader.class).annotatedWith(Names.named("authentication")).toProvider(AuthOpHeaderProvider.class);
 
     bind(OperationHeader.class).annotatedWith(Names.named("delete")).toProvider(DeleteOpHeaderProvider.class);
     bind(OperationHeader.class).annotatedWith(Names.named("update")).toProvider(UpdateOpHeaderProvider.class);
     try {
       SecureRandom random = new SecureRandom();
       bind(SecureRandom.class).toInstance(random);
     } catch (Exception e) {
       throw new RuntimeException("Error initializing secure random for SHA1PRNG", e);
     }
   }
 }
